using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
public partial class admin_SpotCategoryList : admin_BaseUserControl
{
    SpotCategoryDAO daoSpotCate = new SpotCategoryDAO();
    IList<SpotCategory> cateList  = new List<SpotCategory>();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["search"] == "" || Request["search"]==null)
        {            
            LoadData("");
        }else LoadData(Request["search"]);
        
    }
    public void LoadData(string key)
    {
        ActiveAccording = "spot";
        cateList= daoSpotCate.GetAllSpotCategories(key);
        dgrSpotCate.DataSource = cateList;
        dgrSpotCate.DataBind();
    }
    protected void dgrSpotCate_RowEditing(object sender, GridViewEditEventArgs e)
    {
        string id = dgrSpotCate.DataKeys[e.NewEditIndex].Value.ToString();
        Response.Redirect("Default.aspx?ctrl=spot_cate&mode=1&id="+id);
    }
    protected void lnkDelete_Click(object sender, EventArgs e)
    {
        int count = 0;
        bool rs=true;
   
        foreach (GridViewRow row in dgrSpotCate.Rows)
        {      
            bool check = ((CheckBox)row.FindControl("chkChoice")).Checked;
            if (check)
            {
                count++;
                int id = int.Parse(dgrSpotCate.DataKeys[row.RowIndex].Value.ToString());
                if (daoSpotCate.Delete(id) <= 0)
                {                   
                    rs=false;
                    break;
                }
            }
        }
        if (count == 0) ShowMessage("Please specify items to delete");
        else if(rs)
        ShowMessage("Selected items are deleted sucessfully");
        else ShowMessage("Error occured when trying to delete specified categories");
    LoadData("");
    }
    protected void lnkSearch_Click(object sender, EventArgs e)
    {        
        Response.Redirect("Default.aspx?ctrl=spot_cate_list&search="+txtSearch.Text);
    }
    protected void dgrSpotCate_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
       // Response.Write("<script>confirm('Are you sure?');</script>");
        int id = int.Parse(dgrSpotCate.DataKeys[e.RowIndex].Value.ToString());

        if (daoSpotCate.Delete(id) > 0)
        {
            ShowMessage("Deleted successfully");
        }
        else ShowMessage("Error occured when trying to delete specified categories");
        LoadData("");
    }
    protected void dgrSpotCate_RowDeleted(object sender, GridViewDeletedEventArgs e)
    {

    }
}
